import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

/**
 * This class is for getting the names of the players in a nice and neat window. 
 * 
 * @author dsilver
 *
 */
public class NameWindow{
	private JTextField txtEnterName;
	private String name;
	private JFrame nameWindow;
	
	/**
	 *	The constructor makes the window  
	 */
	public NameWindow (){
		createNameWindow();
		
	}
	
	
	public void createNameWindow(){
		final JFrame nameWindow = new JFrame();
		nameWindow.getContentPane().setLayout(null);
		nameWindow.setVisible(true);
		nameWindow.setBounds(100, 100, 300, 100);
		
		txtEnterName = new JTextField();
		txtEnterName.setText("Enter name");
		txtEnterName.setBounds(10, 11, 86, 20);
		nameWindow.getContentPane().add(txtEnterName);
		txtEnterName.setColumns(10);
		txtEnterName.setEditable(true);
		
		JButton btnEnter = new JButton("Enter");
		btnEnter.setBounds(129, 10, 89, 23);
		btnEnter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.out.println("Enter was clicked.");
				name = txtEnterName.getText();
				System.out.println(name+" was the name enterd");
				nameWindow.setVisible(false);
				setName(name);
				System.out.println("Get Name: " + getName());
				
			}
				
		});		
		
		
		
		
		
		nameWindow.getContentPane().add(btnEnter);
		nameWindow.setAlwaysOnTop(true);
		
		
		
	}
	
	
	public void setName(String name){
		this.name = name;
	}
	
	public String getName(){
		
		//String name = "";
		//nameWindow.setVisible(false);
		
		return name;
		
	}
}